﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Htss.Platform.Data;
using Htss.Platform.Web;
using Htss.Platform.Core;

namespace DreamBox.Web.Box
{
    public class registerBox:ControllerBox
    {
        public ActionResult Load()
        {
            if (Request.RequestType == "POST")
            {
                if (Verification())
                {
                    Model.User m = new Model.User();
                    m.UserName = Htss.Platform.Core.Text.Replace(Request.Form["UserName"]);
                    m.Password = Request.Form["Password"];
                    m.Email = "123@723.la";
                    DAL.User.UserInfo user = new DAL.User.UserInfo();
                    GHashTable hash = user.Add(m);
                    if (hash["@ReturnValue"].ToString() == "1")
                    {
                        BLL.Message.Jump(this, "欢迎您的加入!", "/login", "1");
                    }
                    else
                    {
                        BLL.Message.Jump(this, "注册过程中出现异常,您可以尝试重新注册!", "/register", "0");
                    }
                }
            }
            return View("register");
        }
        //验证
        bool Verification()
        {
            DAL.User.UserInfo user = new DAL.User.UserInfo();

            Verify vf = new Verify();
            vf.VerificationMessage = VerificationMessage;
            VerifyField vUserName = vf.NewVerifyField(Request.Form["UserName"],"UserName");
            vUserName.AddNull("请输入用户名");
            vUserName.AddLengthRange("长度范围在1-20之间", 1, 20);
            vUserName.AddCustom("输入的用户名已经注册,请重新输入", user.IsUserName(Request.Form["UserName"]));

            VerifyField vPassword = vf.NewVerifyField(Request.Form["Password"],"Password");
            vPassword.AddNull("此项不能为空");
            vPassword.AddLengthRange("请输入(6-20)之间的密码长度", 6, 20);

            VerifyField vConfirmPassword = vf.NewVerifyField(Request.Form["ConfirmPassword"], "ConfirmPassword");
            vConfirmPassword.AddNull("此项不能为空");
            vConfirmPassword.AddLengthRange("请输入(6-20)之间的密码长度", 6, 20);
            vConfirmPassword.AddCompare("请输入两次相同的密码", Request.Form["Password"]);

            vf.Begin();
            return vf.IsVerify;
        }
    }
}
